package com.module_video.popuputil;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.module_video.R;
import com.zyyoona7.popup.EasyPopup;

/**
 * Created by Administrator on 2020/5/14 0014.
 */

public class OpreateCommentPopup implements View.OnClickListener {

    private Activity activity;
    private String copyContent;

    public OpreateCommentPopup(Activity activity) {

        this.activity = activity;

        initPopuPopu();
    }

    private EasyPopup popu;

    private void initPopuPopu() {
        popu = EasyPopup.create()
                .setContext(activity)
                .setContentView(R.layout.popup_opreatecomment)
                .setWidth(WindowManager.LayoutParams.FILL_PARENT)
                .setHeight(WindowManager.LayoutParams.FILL_PARENT)
                .setOnViewListener(new EasyPopup.OnViewListener() {
                    @Override
                    public void initViews(View view, EasyPopup basePopup) {

                        initView(view);
                    }

                })
                .setFocusAndOutsideEnable(true)
                .apply();

    }

    private LinearLayout linReply, linCopy, linDelete, linReport, linCancel;
    private View view_cancel;

    private void initView(View view) {

        view_cancel = view.findViewById(R.id.view_cancel);

        linReply = view.findViewById(R.id.lin_reply);
        linCopy = view.findViewById(R.id.lin_copy);
        linDelete = view.findViewById(R.id.lin_delete);
        linReport = view.findViewById(R.id.lin_report);
        linCancel = view.findViewById(R.id.lin_cancel);

        linReply.setOnClickListener(this);
        linCopy.setOnClickListener(this);
        linDelete.setOnClickListener(this);
        linReport.setOnClickListener(this);
        linCancel.setOnClickListener(this);
        view_cancel.setOnClickListener(this);

    }

    public void setCopyContent(String copyContent) {
        this.copyContent = copyContent;
    }


    public void dismiss() {
        popu.dismiss();
    }


    public void showAnswerPopuPopu(View view) {
        initPopuPopu();
        popu.showAtLocation(view, Gravity.TOP, 0, 0);

    }


    @Override
    public void onClick(View v) {

        int i = v.getId();
        if (i == R.id.view_cancel) {
            dismiss();
        } else if (i == R.id.lin_cancel) {
            dismiss();
        } else if (i == R.id.lin_reply) {
            if (listener != null) {
                listener.onRelyComment();
            }
        } else if (i == R.id.lin_copy) {

            if (listener != null) {
                listener.onCopyComment(copyContent);
            }

        } else if (i == R.id.lin_delete) {
            if (listener != null) {
                listener.onDeleteComment();
            }
        } else if (i == R.id.lin_report) {
            if (listener != null) {
                listener.onReportComment();
            }
        }
    }

    public void hideDeleteItem() {

        linDelete.setVisibility(View.GONE);
    }


    public interface OpreateListener {

        void onRelyComment();

        void onCopyComment(String copyContent);

        void onDeleteComment();

        void onReportComment();
    }

    public OpreateListener listener;

    public void setOpreateListenerener(OpreateListener opreateListenerener) {

        this.listener = opreateListenerener;

    }


}
